<?php
/**
 * 
 * @author hushuai
 *
 */
class UrlAction extends CommonAction{
	
	public function lbs(){
		
		if(IS_AJAX){
			//$map = json_decode(cookie(C('USER_SELECT_CITY')),true);
			$map  = addressJsonDecode();
			$map['pointlng'] = $this->_param("pointlng","trim","");
			$map['pointlat'] = $this->_param("pointlat","trim","");
			
			//根据百度地图pai获取用户具体位置
			$url        = "http://api.map.baidu.com/geocoder/v2/?ak=v91aIepsmM86gClKu180Zsdb&location=".$map['pointlat'].",".$map['pointlng']."&output=json";
			$data       = json_decode(file_get_contents($url),true);
			
			if($data['status']==0){
				$map['adds']   = $data['result']['formatted_address'];
				$map['enadds'] = Pinyin($data['result']['formatted_address']);
			}
			
			addressJsonEncode($map);
			//cookie(C('USER_SELECT_CITY'),json_encode($map),'3600');
			$this->ajaxReturn(array("status"=>1));
		}else{
			
			$data = getCityInfo();                    //获取用户所在城市 
			$arr  = C('CITY_ARRAY');                  //可选城市数组
			//$map  = json_decode(cookie(C('USER_SELECT_CITY')),true);   //获取用户选择的城市信息
			$map  = addressJsonDecode();
			$lang = getLang();
			
			if($map['city']){
				if($lang=="en-us"){
					$city = $arr[$map['city']];
				}else{
					$city = $map['city'];
				}
			}else{
				$city = $data['city'];
			}
			
			$this->assign("data",$data);
			$this->assign("cityid",$data['city_id']);
			$this->assign("city",$city);
			$this->display();
		}
	}
	
	public function ditu(){
		$this->display();
	}
	
	public function _empty(){
		$action = ACTION_NAME;
		$this->display($action);
	}
}
